﻿$(function() {
		$(".del").click(function() {
			var href = $(this).attr("href");
			$("form").attr("action", href).submit();
			return false;
		});

	})

var loginurl = 'login.html';
/*切换验证码*/
function refresh(obj) {
    $(obj).attr('src', "/valcode?d=" + new Date()*1);
}
function Trim(str){ 
             return str.replace(/(^\s*)|(\s*$)/g, ""); 
 }
function ajaxurl(url, type, data, success) {
    $.ajax({
        url: url,
        type: type,
        dataType: 'json',
        data: data
    })
       .done(function (data) {
         // console.log(JSON.stringify(data));
                  success(data);
             })
         .fail(function (jqXHR) {
                 alert(JSON.stringify(jqXHR));
          });
}
function setCookie(cname, cvalue, exdays)
{
  var d = new Date();
  d.setTime(d.getTime()+(exdays*24*60*60*1000));
  var expires = "expires="+d.toGMTString();
  document.cookie = cname + "=" + cvalue + "; " + expires;
}
var dgstr='';
//导航递归显示
function recursion(jsonObj) {
	if(typeof(jsonObj) == "undefined") {
		alert('JSON对象不能为空！');
	}
	jsonObj = jsonObj.list;			
	//遍历第一层数据
	for(var topKey in jsonObj) {		
		//dgstr +='<li  class="fl">*' + jsonObj[topKey].title;
		dgstr += '<li  class="fl"><a navid="' + jsonObj[topKey].subtitle + '"  target="mainframe" href="' + jsonObj[topKey].linkurl + '">' +
		       '<i class="' + (jsonObj[topKey].cssstyle == "" ? "kg" : jsonObj[topKey].cssstyle) + '"></i><h3>' + jsonObj[topKey].title + '</h3><b class="expandable fa fa-plus"></b></a>';
		if(typeof(jsonObj[topKey].list) == "object") {
			dgstr += '<ul class="yc list">';
			recursion(jsonObj[topKey]);
			dgstr += '</ul>';	
		} 	
		dgstr += '</li>';	
	}
		//console.log("00:"+dgstr);		
};
function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg))
        return arr[2];
    else
        return '';
}
 function isnull(val,charlast) {
                    if (val) {
                        return val;
                    } else {
                    	if(arguments.length==1)
                        return '';
                        else
                        return charlast;
                    }
                };
                
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}

Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //�·� 
        "d+": this.getDate(), //�� 
        "h+": this.getHours(), //Сʱ 
        "m+": this.getMinutes(), //�� 
        "s+": this.getSeconds(), //�� 
        "q+": Math.floor((this.getMonth() + 3) / 3), //���� 
        "S": this.getMilliseconds() //���� 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

//日期加/减几天，默认为当前日期，格式如“2017-08-25”
function addDate(days, date) {
    var d = new Date();
    if (arguments.length == 2) {
        d = new Date(Date.parse(date));
    }

    d.setDate(d.getDate() + days);
    var month = d.getMonth() + 1;
    var day = d.getDate();
    if (month < 10) {
        month = "0" + month;
    }
    if (day < 10) {
        day = "0" + day;
    }
    var val = d.getFullYear() + "-" + month + "-" + day;
    return val;
}

function addDateMonth(months) {
   var d = new Date();
				var d = new Date(d.getFullYear(), d.getMonth(), 1);
				d.setMonth(d.getMonth() + months);
				var month = d.getMonth() + 1;
				if(month < 10) {
					month = "0" + month;
				}
				var val = d.getFullYear() + "-" + month;
				return val;
}

// date2-date 相差几天
function datediff(date, date2) {
    var currdate = new Date(Date.parse(date));
    date2 = new Date(Date.parse(date2));
    var date3 = date2.getTime() - currdate.getTime()  //时间差的毫秒数
    if(arguments.length==1)
    date3=currdate.getTime()-new Date(addDate(0)).getTime();
    //计算出相差天数
    var days = Math.floor(date3 / (24 * 3600 * 1000))
    /*
     var leave1 = date3 % (24 * 3600 * 1000)    //计算天数后剩余的毫秒数
     var hours = Math.floor(leave1 / (3600 * 1000))
     //计算相差分钟数
     var leave2 = leave1 % (3600 * 1000)        //计算小时数后剩余的毫秒数
     var minutes = Math.floor(leave2 / (60 * 1000))
     //计算相差秒数
     var leave3 = leave2 % (60 * 1000)      //计算分钟数后剩余的毫秒数
     var seconds = Math.round(leave3 / 1000)
     */
    return days;
}

//��ȡurl�еĲ���
function getUrlParam(name, defaultvalue) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //����һ������Ŀ������������ʽ����
    var r = window.location.search.substr(1).match(reg);  //ƥ��Ŀ�����
    if (r != null)
        return decodeURI(r[2]);
    if (arguments.length == 2)
        return defaultvalue;
    return null;
}

/* ����ͼ��ʽ  */
function focuview(obj) {
    var i = 0;
    var ol = "<ol class=\"carousel-indicators\">";
    $(obj + ' .item').each(function () {
        if (i == 0) {
            $(this).addClass("active");
        }
        ol += "<li  data-target=\"" + obj + "\" data-slide-to=" + i + " class=" + (i == 0 ? "active" : "") + "></li>";
        i++;
    });
    ol += "</ol>";
    ol += '<a class="prev0" href="#' + obj + '" role="button" data-slide="prev"></a>'
    ol += '<a class="next0" href="#' + obj + '" role="button" data-slide="next"></a>';
    $(ol).appendTo(obj);
}
function changeTwoDecimal_f(x, per) {
    var f_x = parseFloat(x);
    if (isNaN(f_x)) {
        return 0;
    }
    var isminus=false;
    if (x < 0) {
        isminus = true;
        f_x = Math.abs(f_x);
    }   
    f_x = Math.round(f_x * 100) / 100;
    var s_x = f_x.toString();
    var pos_decimal = s_x.indexOf('.');
    if (pos_decimal < 0) {
        pos_decimal = s_x.length;
        s_x += '.';
    }
    while (s_x.length <= pos_decimal + 2) {
        s_x += '0';
    }
    // return s_x;
    if (s_x.indexOf(".") > -1)
        var number = s_x.substr(0, s_x.indexOf("."));
    else
        number = s_x;
    if (number.length <= 3)
        return (isminus ? '-' : '') + s_x;
    else {
        var mod = number.length % 3;
        var output = (mod == 0 ? '' : (number.substring(0, mod)));
        for (i = 0; i < Math.floor(number.length / 3) ; i++) {
            if ((mod == 0) && (i == 0))
                output += number.substring(mod + 3 * i, mod + 3 * i + 3);
            else
                output += ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
        }
        if (per > 0)
            return (isminus?'-':'')+ output + s_x.substr(s_x.indexOf("."), 3);
        else
            return (isminus ? '-' : '') + output;

    }
};


var day=addDate(0);
	   var LODOP; //声明为全局变量 
        function preview(areaid) {
            LODOP = getLodop();
            var strBodyStyle = "<style>table,td,th{padding:8px 2px;border-collapse:collapse;line-height:20px;background:none; }</style>";
            var strFormHtml = strBodyStyle + "<body>" + document.getElementById(areaid).innerHTML + "</body>";
            LODOP.PRINT_INIT("会员列表"+day);
            LODOP.SET_PRINT_STYLE("FontSize", 12);
            LODOP.SET_PRINT_STYLE("Bold", 1);
            LODOP.ADD_PRINT_HTM(20, 20, "RightMargin:0.5cm", "BottomMargin:4mm", strFormHtml);
            LODOP.PREVIEW();
        };       
       
        function save(areaid) {
            LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
            LODOP.PRINT_INIT("");
            LODOP.ADD_PRINT_TABLE(100, 20, 500, 80, document.getElementById(areaid).innerHTML);
            //		LODOP.SET_SAVE_MODE("QUICK_SAVE",true);//快速生成（无表格样式,数据量较大时或许用到）
            LODOP.SAVE_TO_FILE("会员列表_"+day+".xls");
        };
       
        //页面内容打印
function print(areaid){
Item=document.getElementById(areaid).innerHTML;
status='fullscreen';
//status="width=0,height=0";
MsgBox=window.open("","print",status);
MsgBox.document.write('<html><head><title></title></head><body><div width=100% >');
MsgBox.document.write('<style>.dyc{display:none;}a {text-decoration: none;}table{border:1px solid #ccc;margin:0;padding:0;}table td, table  th{font-size:12px; padding:4px 2px;text-align:center; border-collapse:collapse;line-height:20px;background:none;border-right:1px solid #ddd;border-bottom:1px solid #ddd;}	</style>');
MsgBox.document.write(""+Item+"");
MsgBox.document.write("</div></body></html>");
MsgBox.document.close();
MsgBox.print();
MsgBox.close();
}


// xdata= ['出租车', '公交车', '滴滴快车', '私家车', '其它'],
// valuedata=[4541, 2234, 3822, 3475, 1263];
function chartbarSignel(id, title, xdata, valuedata, labelcenter) {
    var myChart5 = echarts.init(document.getElementById(id), 'macarons');
    option = {
        title: {
            text: title,
            x: 'center'
        },
        //	color: ['#3398DB'],
        tooltip: {
            trigger: 'axis',
            axisPointer: { // 坐标轴指示器，坐标轴触发有效
                type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: [{
            type: 'category',
            data: xdata,
            axisTick: {
                alignWithLabel: true
            }
        }],
        yAxis: [{
            type: 'value'
        }],
        series: [{
            name: '',
            type: 'bar',
            barWidth: '60%',
            label: {
                normal: {
                    show: true,
                    position: labelcenter ? 'inside' : 'top'
                }
            },
            data: valuedata
        }]
    };
    myChart5.setOption(option);
}

//var xname=['蒸发量','降水量'];
//var xdata=['1月','2月','3月'];
//var valuedata=[[1,2,3],[4,5,6]]
//chartbarMonth('sex','测试bar',xname,xdata,arr,1);
function chartbarMonth(id, title, xname, xdata, valuedata, labelcenter) {
    var xseris = new Array();
    for (var i = 0; i < valuedata.length; i++) {
        xseris[i] = new Object({
            name: xname[i],
            type: 'bar',
           // stack: 'fee',分组排成一行
            label: { normal: { show: true, position: labelcenter ? 'inside' : 'top' } },
            data: valuedata[i],
           // markPoint: { data: [{ type: 'max', name: '最大值' }] }
        });
    }
    var myChart = echarts.init(document.getElementById(id), 'macarons');
    var option = {
        title: {
            text: title,
            subtext: ''
        },
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: xname
        },
        toolbox: {
            show: true,
            feature: {
                mark: {
                    show: true
                },
                //  dataView: { show: true, readOnly: false },  显示数据类型切换标志
                magicType: {
                    show: true,
                    type: ['line', 'bar']
                },
                // restore: { show: true },
                saveAsImage: {
                    show: true
                }
            }
        },
        calculable: true,
        grid: {
            backgroundColor: '#000',
            borderWidth: '2px',
            borderColor: '#f00'
        },
        xAxis: [{
            splitLine: {
                show: true
            },
            splitArea: {
                show: true
            },
            type: 'category',
            axisLine: {
                onZero: false
            },
            data: xdata
        }],
        yAxis: [{
            splitLine: {
                show: true
            },
            splitArea: {
                show: false
            },
            type: 'value'

        }],
        series: xseris
        /*series: [{
				name: '放贷本金',
				type: 'bar',
				label: {
					normal: {
						show: true,
						position: 'inside'
					}
				},
				data: [2.0, 4.9, 7.0],
				markPoint: {
					data: [{
						type: 'max',
						name: '最大值'
					}]
				}
			},
			{
				name: '净利润',
				type: 'bar',
				// label: { normal: { show: true, position: 'inside' } },
				data: [2.6, 5.9, 5.4],
				markPoint: {
					data: [{
						type: 'max',
						name: '最大值'
					}]
				}
			}
		]
	*/
    };
    myChart.setOption(option);
}

/**
 *  饼形图
 * @param id "chart1"
 * @param {xdata} ['男性', '女性']
 * @param {valuedata} [{value: 5467,name: '男性'},{value: 4533,name: '女性'}]
 */
function chartpie(id, title, xdata, valuedata, labelinside) {
    var myChart3 = echarts.init(document.getElementById(id), 'macarons');
    var option = {
        title: {
            text: title,
            x: 'center'
        },
        tooltip: {
            trigger: 'item',
            formatter: "{b} : {c}人 "
        },

        legend: {
            orient: 'vertical',
            left: 'left',
            data: xdata
        },
        series: [{
            name: '',
            type: 'pie',
            radius: '55%',
            center: ['50%', '60%'],
            data: valuedata,
            label: {
                normal: {
                    position: labelinside ? 'inside' : '0'
                }
            },
            itemStyle: {
                normal: {
                    label: {
                        show: true,
                        formatter: '{b}  \n\n {d}%'
                    },
                    labelLine: {
                        show: true
                    }
                },
                emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }]
    };
    myChart3.setOption(option);
}
